package com.audi.utils;

import android.content.Context;

import com.audi.R;
import com.audi.box.adapter.SQLiteAsusHelperDevice;
import com.audi.box.adapter.SQLiteAsusHelperMember;
import com.audi.box.adapter.SQLiteAsusHelperPlace;
import com.audi.box.adapter.SQLiteAsusHelperScene;
import com.audi.box.adapter.SQLiteAsusNewHelper;
import com.audi.dto.DeviceItem;
import com.audi.dto.HistoryActionSmartTriggerDto;
import com.audi.dto.HistoryDeviceItemAddRemove;
import com.audi.dto.HistoryMemberItem;
import com.audi.dto.MemberItem;
import com.audi.dto.PlaceItem;
import com.audi.dto.SceneItem;

public class DBHelper {

	public static void addDataTest(Context context) {

		SQLiteAsusHelperDevice deviceHelper = new SQLiteAsusHelperDevice(
				context);
		SQLiteAsusHelperPlace placeHelper = new SQLiteAsusHelperPlace(context);
		SQLiteAsusHelperScene sceneHelper = new SQLiteAsusHelperScene(context);
		if (deviceHelper.getListDevice(0).size() < 1) {

			DeviceItem item5 = new DeviceItem();
			item5.setDeviceName("Temperature 3");
			item5.setDeviceIcon("");
			item5.setDeviceStatus(21);
			item5.setDeviceType(Constants.DEVICE_TYPE.STATUSTEMPERATURE
					.ordinal());
			item5.setStatusValue(21);
			item5.setDeviceCode("SSSS");
			item5.setDeviceBoxId(0);
			item5.setDevicePlaceId(3);
			item5.setUserId(1);
			deviceHelper.addDevice(item5);

			DeviceItem item15 = new DeviceItem();
			item15.setDeviceName("Door 1");
			item15.setDeviceIcon("");
			item15.setDeviceStatus(21);
			item15.setDeviceType(Constants.DEVICE_TYPE.ONOFFDOORLOCK.ordinal());
			item15.setStatusValue(1);
			item15.setDeviceCode("SSSS");
			item15.setDeviceBoxId(0);
			item15.setDevicePlaceId(3);
			item15.setUserId(1);
			deviceHelper.addDevice(item15);

			DeviceItem item6 = new DeviceItem();
			item6.setDeviceName("Plug 2");
			item6.setDeviceIcon("");
			item6.setDeviceStatus(1);
			item6.setDeviceType(Constants.DEVICE_TYPE.ONOFFPLUG.ordinal());
			item6.setStatusValue(1);
			item6.setDeviceCode("QQQQ");
			item6.setDeviceBoxId(0);
			item6.setDevicePlaceId(2);
			item6.setUserId(1);
			deviceHelper.addDevice(item6);

			DeviceItem item7 = new DeviceItem();
			item7.setDeviceName("Plug 3");
			item7.setDeviceIcon("");
			item7.setDeviceStatus(1);
			item7.setDeviceType(Constants.DEVICE_TYPE.ONOFFPLUG.ordinal());
			item7.setStatusValue(1);
			item7.setDeviceCode("QQQQ");
			item7.setDeviceBoxId(0);
			item7.setDevicePlaceId(2);
			item7.setUserId(1);
			deviceHelper.addDevice(item7);

			DeviceItem item8 = new DeviceItem();
			item8.setDeviceName("Gas 2");
			item8.setDeviceIcon("");
			item8.setDeviceStatus(1);
			item8.setDeviceType(Constants.DEVICE_TYPE.WARNINGGAS.ordinal());
			item8.setStatusValue(0);
			item8.setDeviceCode("WWWW");
			item8.setDeviceBoxId(0);
			item8.setDevicePlaceId(2);
			item8.setUserId(1);
			deviceHelper.addDevice(item8);

			DeviceItem item9 = new DeviceItem();
			item9.setDeviceName("Gas 3");
			item9.setDeviceIcon("");
			item9.setDeviceStatus(1);
			item9.setDeviceType(Constants.DEVICE_TYPE.WARNINGGAS.ordinal());
			item9.setStatusValue(0);
			item9.setDeviceCode("WWWW");
			item9.setDeviceBoxId(0);
			item9.setDevicePlaceId(2);
			item9.setUserId(1);
			deviceHelper.addDevice(item9);

			DeviceItem item10 = new DeviceItem();
			item10.setDeviceName("Plug 10");
			item10.setDeviceIcon("");
			item10.setDeviceStatus(1);
			item10.setDeviceType(Constants.DEVICE_TYPE.ONOFFPLUG.ordinal());
			item10.setStatusValue(1);
			item10.setDeviceCode("QQQQ");
			item10.setDeviceBoxId(0);
			item10.setDevicePlaceId(3);
			item10.setUserId(1);
			deviceHelper.addDevice(item10);

			DeviceItem item11 = new DeviceItem();
			item11.setDeviceName("Plug 11");
			item11.setDeviceIcon("");
			item11.setDeviceStatus(1);
			item11.setDeviceType(Constants.DEVICE_TYPE.ONOFFLIGHTING.ordinal());
			item11.setStatusValue(1);
			item11.setDeviceCode("QQQQ");
			item11.setDeviceBoxId(0);
			item11.setDevicePlaceId(1);
			item11.setUserId(1);
			deviceHelper.addDevice(item11);

			DeviceItem item12 = new DeviceItem();
			item12.setDeviceName("Plug 12");
			item12.setDeviceIcon("");
			item12.setDeviceStatus(1);
			item12.setDeviceType(Constants.DEVICE_TYPE.ONOFFPLUG.ordinal());
			item12.setStatusValue(1);
			item12.setDeviceCode("QQQQ");
			item12.setDeviceBoxId(0);
			item12.setDevicePlaceId(2);
			item12.setUserId(1);
			deviceHelper.addDevice(item12);
			DeviceItem item1 = new DeviceItem();
			item1.setDeviceName("Alarm");
			item1.setDeviceIcon("");
			item1.setDeviceStatus(1);
			item1.setDeviceType(Constants.DEVICE_TYPE.WARNINGALARM.ordinal());
			item1.setStatusValue(1);
			item1.setDeviceCode("QQQQ");
			item1.setDeviceBoxId(0);
			item1.setDevicePlaceId(5);
			item1.setUserId(1);
			item1.setFavorite(4);
			deviceHelper.addDevice(item1);

			DeviceItem item2 = new DeviceItem();
			item2.setDeviceName("Plug 1");
			item2.setDeviceIcon("");
			item2.setDeviceStatus(0);
			item2.setDeviceType(Constants.DEVICE_TYPE.ONOFFPLUG.ordinal());
			item2.setStatusValue(0);
			item2.setDeviceCode("WWWW");
			item2.setDeviceBoxId(0);
			item2.setDevicePlaceId(2);
			item2.setUserId(1);
			item2.setFavorite(3);
			deviceHelper.addDevice(item2);

			DeviceItem item3 = new DeviceItem();
			item3.setDeviceName("Temp 1");
			item3.setDeviceIcon("");
			item3.setDeviceStatus(25);
			item3.setDeviceType(Constants.DEVICE_TYPE.STATUSTEMPERATURE
					.ordinal());
			item3.setStatusValue(25);
			item3.setDeviceCode("SSSS");
			item3.setDeviceBoxId(0);
			item3.setDevicePlaceId(3);
			item3.setUserId(1);
			item3.setFavorite(2);
			deviceHelper.addDevice(item3);

			DeviceItem item4 = new DeviceItem();
			item4.setDeviceName("Plug 2");
			item4.setDeviceIcon("");
			item4.setDeviceStatus(1);
			item4.setDeviceType(Constants.DEVICE_TYPE.ONOFFPLUG.ordinal());
			item4.setStatusValue(1);
			item4.setDeviceCode("SSSS");
			item4.setDeviceBoxId(0);
			item4.setDevicePlaceId(3);
			item4.setUserId(1);
			item4.setFavorite(1);
			deviceHelper.addDevice(item4);
			// data place

			PlaceItem itempPlace1 = new PlaceItem();
			itempPlace1.setPlaceName("Living Room");
			itempPlace1.setPlaceImage("");
			itempPlace1.setCapabilityType(Constants.PLACE_CAPABILITY.PUBLIC
					.ordinal());
			placeHelper.addPlace(itempPlace1);

			PlaceItem itempPlace2 = new PlaceItem();
			itempPlace2.setPlaceName("My Room");
			itempPlace2.setPlaceImage("");
			itempPlace2.setCapabilityType(Constants.PLACE_CAPABILITY.PUBLIC
					.ordinal());
			placeHelper.addPlace(itempPlace2);

			PlaceItem itempPlace3 = new PlaceItem();
			itempPlace3.setPlaceName("My Room 1");
			itempPlace2.setPlaceImage("");
			itempPlace3.setCapabilityType(Constants.PLACE_CAPABILITY.PUBLIC
					.ordinal());
			placeHelper.addPlace(itempPlace3);

			PlaceItem itempPlace4 = new PlaceItem();
			itempPlace4.setPlaceName("My Room 2");
			itempPlace2.setPlaceImage("");
			itempPlace4.setCapabilityType(Constants.PLACE_CAPABILITY.PUBLIC
					.ordinal());
			placeHelper.addPlace(itempPlace4);

			

			// Add data in table TABLE_HISTORY_PLACE

			/*
			 * HistoryPlaceItem historyPlaceItem = new HistoryPlaceItem(); Date
			 * date= new Date(); String formatStringDate="MMM dd, yyyy";
			 * historyPlaceItem.setHistoryPlacePlaceId(2);
			 * historyPlaceItem.setHistoryPlaceType(1);
			 * historyPlaceItem.setHistoryPlaceUserId(1);
			 * historyPlaceItem.setHistoryPlaceDate
			 * (DateUtil.convertDateToString(date, formatStringDate));
			 * mSQLHelper.addHistoryPlace(historyPlaceItem);
			 */

			// dump user
			// MemberItem userItem1 = new MemberItem();
			// userItem1.setMemberName("Admin");
			// userItem1.setMemberEmail("admin@gmail.com");
			// userItem1.setMemberPhoto("");
			// userItem1.setMemberStatus(0);
			// mSQLHelper.addMember(userItem1);
			//
			// MemberItem userItem2 = new MemberItem();
			// userItem2.setMemberName("Member 1");
			// userItem2.setMemberEmail("member1@gmail.com");
			// userItem2.setMemberPhoto("");
			// userItem2.setMemberStatus(1);
			// mSQLHelper.addMember(userItem2);
			//
			// MemberItem userItem3 = new MemberItem();
			// userItem3.setMemberName("Member 2");
			// userItem3.setMemberEmail("member2@gmail.com");
			// userItem3.setMemberPhoto("");
			// userItem3.setMemberStatus(0);
			// mSQLHelper.addMember(userItem3);
			//
			// MemberItem userItem4 = new MemberItem();
			// userItem4.setMemberName("Member 3");
			// userItem4.setMemberEmail("member3@gmail.com");
			// userItem4.setMemberPhoto("");
			// userItem4.setMemberStatus(0);
			// mSQLHelper.addMember(userItem4);
		}
	}

	public static void addMemberTest(Context context) {
		// Add data member

		SQLiteAsusHelperMember SQLHelperMember = new SQLiteAsusHelperMember(
				context);
		if (SQLHelperMember.getListMember().size() < 1) {
			MemberItem memberItem1 = new MemberItem();
			memberItem1.setMemberName("Mary");
			memberItem1.setMemberEmail("mary@gmail.com");
			memberItem1.setMemberPhoto("");
			memberItem1.setMemberStatus(0);
			SQLHelperMember.addMember(memberItem1);

			MemberItem memberItem2 = new MemberItem();
			memberItem2.setMemberName("Johnson");
			memberItem2.setMemberEmail("johnson@gmail.com");
			memberItem2.setMemberPhoto("");
			memberItem2.setMemberStatus(0);
			SQLHelperMember.addMember(memberItem2);

			MemberItem memberItem3 = new MemberItem();
			memberItem3.setMemberName("Kate");
			memberItem3.setMemberEmail("kate@gmail.com");
			memberItem3.setMemberPhoto("");
			memberItem3.setMemberStatus(0);
			SQLHelperMember.addMember(memberItem3);

			MemberItem memberItem4 = new MemberItem();
			memberItem4.setMemberName("Melisa");
			memberItem4.setMemberEmail("melisa@gmail.com");
			memberItem4.setMemberPhoto("");
			memberItem4.setMemberStatus(0);
			SQLHelperMember.addMember(memberItem4);

			MemberItem memberItem5 = new MemberItem();
			memberItem5.setMemberName("Jonathan");
			memberItem5.setMemberEmail("jonathan@gmail.com");
			memberItem5.setMemberPhoto("");
			memberItem5.setMemberStatus(0);
			SQLHelperMember.addMember(memberItem5);

			MemberItem memberItem6 = new MemberItem();
			memberItem6.setMemberName("Peter");
			memberItem6.setMemberEmail("peter@gmail.com");
			memberItem6.setMemberPhoto("");
			memberItem6.setMemberStatus(0);
			SQLHelperMember.addMember(memberItem6);

			MemberItem memberItem7 = new MemberItem();
			memberItem7.setMemberName("Scott");
			memberItem7.setMemberEmail("scott@gmail.com");
			memberItem7.setMemberPhoto("");
			memberItem6.setMemberStatus(0);
			SQLHelperMember.addMember(memberItem7);
		}

	}

	public void addSceneTest(Context context) {
		SQLiteAsusHelperScene SQLHelperScene = new SQLiteAsusHelperScene(
				context);
		if (SQLHelperScene.getListScene().size() < 1) {
			SceneItem itemScene1 = new SceneItem();
			itemScene1.setSceneTitle("Movie");
			itemScene1.setSceneIcon("");
			itemScene1.setPlaceId(2);
			itemScene1.setSceneBackground(Constants.SCENE_COLOR_TYPE.YELLOW
					.ordinal());
			// itemScene1.setScenePlace("My room");
			SQLHelperScene.addScene(itemScene1);

			SceneItem itemScene2 = new SceneItem();
			itemScene2.setSceneTitle("Reading");
			itemScene2.setSceneIcon("");
			itemScene2.setPlaceId(2);
			itemScene2.setSceneBackground(Constants.SCENE_COLOR_TYPE.SBLUE
					.ordinal());
			// itemScene2.setScenePlace("My room");
			SQLHelperScene.addScene(itemScene2);

			SceneItem itemScene3 = new SceneItem();
			itemScene3.setSceneTitle("Morning");
			itemScene3.setSceneIcon("");
			itemScene3.setPlaceId(3);
			itemScene3.setSceneBackground(Constants.SCENE_COLOR_TYPE.SBLUE
					.ordinal());
			SQLHelperScene.addScene(itemScene3);
		}
	}

	public static void addHistoryMemberStatus(SQLiteAsusNewHelper mSQLHelper,
			int id, int type) {
		// Add data member action
		HistoryMemberItem item = new HistoryMemberItem();

		item.setHistoryMemberMemberId(id);
		item.setHistoryMemberType(type);

		String mydate = String.valueOf(System.currentTimeMillis());
		item.setHistoryMemberDate(mydate);
		mSQLHelper.addDataBase_history_member_action(item);
		//
	}

	// add data action smart trigger

	public static void addDataToHistoryDevice(SQLiteAsusNewHelper mSQLite,
			int id, int userid, String deviceName, int type,
			int deviceTypeType, String username, String placename, String date) {

		HistoryDeviceItemAddRemove item = new HistoryDeviceItemAddRemove();

		item.setDeviceId(id);
		item.setUserId(userid);
		item.setDeviceType(type);
		item.setUserName(username);
		String mydate = String.valueOf(System.currentTimeMillis());
		item.setDateTime(mydate);
		item.setPlaceName(placename);
		item.setDeviceName(deviceName);
		mSQLite.addDataToHistoryDevice(item);

	}

	public static void addDataToHistorySmartTrigger(
			SQLiteAsusNewHelper mSQLite, int whenTriggerId, int userId,
			int typeTrigger)

	{

		HistoryActionSmartTriggerDto item_history = new HistoryActionSmartTriggerDto();
		item_history.setWhenId(whenTriggerId);
		item_history.setType(typeTrigger); // its up to action.
		item_history.setUserId(userId); // get current user!
		String mydate = String.valueOf(System.currentTimeMillis());
		item_history.setDate(mydate);
		mSQLite.addHistoryActionSmartTrigger(item_history);

	}

}
